"""Common instrumentation data structures."""

from __future__ import annotations

from dataclasses import dataclass, field
from pathlib import Path
from typing import List, Optional


@dataclass
class InstrumentationConfig:
    """User-facing configuration for instrumentation passes."""

    profile: str = "gptl"
    language: str = "fortran"
    apply: bool = False
    include_functions: Optional[List[str]] = None
    exclude_functions: Optional[List[str]] = None


@dataclass
class InstrumentationPatch:
    """Represents a planned source modification."""

    path: Path
    original: str
    modified: str
    description: str = ""

    def has_changes(self) -> bool:
        return self.original != self.modified


class Instrumenter:
    """Abstract helper for source instrumentation."""

    def plan(self, path: Path, config: InstrumentationConfig) -> InstrumentationPatch:
        raise NotImplementedError


def should_process(function_name: str, config: InstrumentationConfig) -> bool:
    """Utility to decide if a function should be instrumented."""

    if config.include_functions:
        if function_name.lower() not in {name.lower() for name in config.include_functions}:
            return False

    if config.exclude_functions and function_name.lower() in {name.lower() for name in config.exclude_functions}:
        return False

    return True
